<?php
	error_reporting(E_ALL || ~E_NOTICE);
	$i=1;  
	$sqlstr='';
	$servertab='';
	$dbResult=array();
    $myconn=@mysql_connect("localhost","root","root");
    if(!$myconn)
    {
        $string = "Can't connect database : ".mysql_error();
        file_put_contents("test.log", $string, FILE_APPEND);
	    die('Could not connect: '.mysql_error());
		return;
    }
    $db_selected=mysql_select_db("dwaccessDB",$myconn);
	if(!$db_selected)
    {        
	    die("Can't use database dwaccessDB : ".mysql_error());
        $string = "Can't use database : ".mysql_error();
        file_put_contents("test.log", $string, FILE_APPEND);
		mysql_close($myconn);
		return;
	}
		
	$strSql="select serverIP,serverPORT,cmdresultpath,realtimepath,DetectDevicepath,Camera0ADDR,Camera0PORT,Camera1ADDR,Camera1PORT,Camera2ADDR,Camera2PORT,Camera3ADDR,Camera3PORT,reQusttime,sVersion from serversetting;";
	$result=mysql_query($strSql,$myconn);	        
//    @file_put_contents("test.log", "\n strSql =".$strSql."\n", FILE_APPEND);
	while($dbResult = mysql_fetch_array($result))
	{	        		   
		for($j=0;$j<15;$j++)
		{			   
			if($i==1 && $j==0)
		    {			        
				$servertab = "{\"s".$i.'_'.$j."\":\"".$dbResult[$j].'"';						
		    }else
		    {
		        $servertab = $servertab.",\"s".$i.'_'.$j."\":\"".$dbResult[$j].'"';
		    }
		}
        $i++;	
//			@file_put_contents("test.log", "\n i =".$i." gatetab =".$dbResult[$i-1]."\n", FILE_APPEND);				
	}
	if($i===1)
	{
	    for($j=0;$j<15;$j++)
		{
		    if($j==0)
			{  
			    $servertab = "{\"s1_".$j."\":\" \"";	
		    }else
			{
			    $servertab = $servertab.",\"s1_".$j."\":\" \"";
			}
		}
	}	
//    $servertab = $servertab.",\"nrows\":\"".($i-1)."\",\"ncols\":\"6\"}";
	$servertab = $servertab.",\"nrows\":\"".($i-1)."\",\"ncols\":\"15\"}";
	mysql_free_result($result);
	mysql_close($myconn);	
	echo $servertab;
//    @file_put_contents("test.log", "\n servertab =".$servertab."\n", FILE_APPEND);
			
	exit(0);    
?>